<template>
  <div class="mcontainer">
    <div class="serach-option">
      <el-form :model="queryParams" ref="queryRef" :inline="true" class="search-form" @submit.prevent label-width="100px">
        <el-form-item label="测试用例id" prop="code">
          <el-input v-model="queryParams.code" placeholder="请输入测试用例id" clearable />
        </el-form-item>
        <el-form-item label="测试用例名称" prop="name">
          <el-input v-model="queryParams.name" placeholder="请输入测试用例名称" clearable />
        </el-form-item>
        <div v-show="false">
          <el-form-item label="需求id" prop="pageNum"></el-form-item>
          <el-form-item label="需求id" prop="pageSize"></el-form-item>
        </div>
        <el-form-item>
          <el-button type="primary" @click="getList">搜索</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- <div class="createValue">
      <el-button type="primary" icon="Download" @click="handleButtonClick('download')">下载</el-button>
    </div> -->

    <div class="table-container">
      <el-table :data="tableData" @selection-change="handleSelectionChange" border>
        <!-- <el-table-column type="selection" width="55"></el-table-column> -->
        <el-table-column prop="code" label="测试用例id" min-width="200"></el-table-column>
        <el-table-column prop="name" label="测试用例名称" min-width="200"></el-table-column>
        <el-table-column prop="type" label="测试用例类型类型" min-width="100"></el-table-column>
        <el-table-column prop="relatedReqId" label="关联需求id" min-width="200">
          <template #default="scope">
            <div v-for="(item, ind) in (scope.row.intToolDataRequirements || [])" :key="ind">
              {{ item.requirementItemId }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="createBy.nickName" label="创建人" width="200"></el-table-column>
        <el-table-column prop="updateTime" label="更新时间" width="180" />
        <el-table-column fixed="right" label="操作" width="160">
          <template #default="scope">
            <el-button link type="primary" @click="handleButtonClick('view', scope.row)">查看</el-button>
            <el-button link type="primary" @click="handleButtonClick('edit', scope.row)">编辑</el-button>
            <el-button link type="primary" @click="projectAPI.downloadFile(scope.row.fileVersionId)">下载</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
    <ViewDialog v-if="viewDialogVisible" v-model="viewDialogVisible" :title="viewDialogTitle" :data="viewDialogData" :isEdit="isEdit" />
  </div>
</template>

<script setup>
import ViewDialog from './components/ViewDialog.vue';
import { ref } from 'vue';
import * as projectAPI from '@/api/project'
const queryParams = ref({
  types: ['test-case'],
  code: '',
  name: '',
  creator: '',
  pageNum: 1,
  pageSize: 10
});
const loading = ref(false);
const queryRef = ref(null);
const selectedRows = ref([]);
const viewDialogVisible = ref(false);
const viewDialogTitle = ref('测试用例详情');
const viewDialogData = ref({});
const isEdit = ref(false);
const total = ref(0)
//检索全部数据，筛选数据
const searchTableData = async () => {
  loading.value = true;
  projectAPI.geAllList(queryParams.value).then(res => {
    let data = res.data || {};
    tableData.value = data.records || [];
    total.value = data.total || 0
  }).finally(()=>loading.false = true)
};
const tableData = ref([]);

const getList = async () => {
  searchTableData();
};

const handleReset = () => {
  queryRef.value.resetFields();
  getList();
};

const handleButtonClick = (flag, row) => {
  switch (flag) {
    case 'add':
      break;

    case 'download':
      break;
    case 'view':
      viewDialogData.value = row;
      viewDialogVisible.value = true;
      isEdit.value = false;
      break;
    case 'edit':
      viewDialogData.value = row;
      viewDialogVisible.value = true;
      isEdit.value = true;
      break;
  }
};

const handleSelectionChange = (selection) => {
  selectedRows.value = selection;
};
getList()
</script>

<style scoped lang="scss">


.custom-add-btn {
  margin-left: 20px;
  margin-right: 10px;
}

.createValue {
  margin-left: 20px;
  margin-bottom: 10px;
}
</style>
